package com.example.pipline.yu.normal;

import java.util.HashMap;
import java.util.Map;

// 上下文对象：在步骤间传递数据
public class PipelineContext {
    private final Map<String, Object> data = new HashMap<>();
    private boolean hasError = false;
    private String errorMessage;

    // 设置数据
    public void set(String key, Object value) {
        data.put(key, value);
    }

    // 获取数据
    @SuppressWarnings("unchecked")
    public <T> T get(String key) {
        return (T) data.get(key);
    }

    // 错误处理
    public void setError(String message) {
        this.hasError = true;
        this.errorMessage = message;
    }

    public boolean hasError() {
        return hasError;
    }

    public String getErrorMessage() {
        return errorMessage;
    }
}